package com.tanjie.blackbean.iot.simulator.task;

import com.tanjie.blackbean.iot.simulator.model.constant.MqttMeta;
import com.tanjie.blackbean.iot.simulator.model.constant.MqttTopicMeta;
import com.tanjie.blackbean.iot.simulator.model.constant.SensorScheduleTaskMeta;
import com.tanjie.blackbean.mqtt.support.BlackbeanMqttUtil;
import com.tanjie.blackbean.schedule.support.AbstractTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * @Author tanjie
 * @Date 2022/6/23 下午3:25 周四
 **/
@Slf4j
@Component
public class DeviceHeartbeatTask extends AbstractTask {

    @Override
    public String getTaskName() {
        return SensorScheduleTaskMeta.DEVICE_HEARTBEAT;
    }

    @Override
    public void run() {
        Random random = new Random();
        int value = random.nextInt(100);
        BlackbeanMqttUtil.send(MqttMeta.EMQ_PRODUCER_LOCAL, MqttTopicMeta.SENSOR_UPLOAD_TEMPERATURE, String.valueOf(value));
        log.info("upload temperature");
    }

}
